#ifndef _DRVRTC_T_H_
#define _DRVRTC_T_H_

/* S3C2440 rtc 寄存器 */

#define S3C2440_REG_RTCCON      0x57000040    /* RTC ontrol */
#define S3C2440_REG_TICNT       0x57000044    /* Tick time count */
#define S3C2440_REG_RTCALM      0x57000050    /* RTC alarm control */
#define S3C2440_REG_ALMMIN      0x57000058    /* Alarm minute */
#define S3C2440_REG_ALMSEC      0x57000054    /* Alarm second */
#define S3C2440_REG_ALMHOUR     0x5700005c    /* Alarm hour */
#define S3C2440_REG_ALMDATE     0x57000060    /* Alarm day */
#define S3C2440_REG_ALMMON      0x57000064    /* Alarm month */
#define S3C2440_REG_ALMYEAR     0x57000068    /* Alarm year */
#define S3C2440_REG_BCDSEC      0x57000070    /* BCD second */
#define S3C2440_REG_BCDMIN      0x57000074    /* BCD minute */
#define S3C2440_REG_BCDHOUR     0x57000078    /* BCD hour */
#define S3C2440_REG_BCDDATE     0x5700007c    /* BCD day */
#define S3C2440_REG_BCDDAY      0x57000080    /* BCD date */
#define S3C2440_REG_BCDMON      0x57000084    /* BCD month */
#define S3C2440_REG_BCDYEAR     0x57000088    /* BCD year */

/* S3C2440 寄存器设置 */

#define S3C2440_RTCCTL_EN       (1 << 0)      /* RTC控制使能 */
#define S3C2440_RTCTICK_INT_EN  (1 << 7)      /* 使能 RTC节拍 中断 */
#define S3C2440_RTCALM_INT_EN   (1 << 6)      /* 使能 RTC闹钟 中断 */
#define S3C2440_RTCALM_HOUR_EN  (1 << 2)      /* 使能ALARM hour */
#define S3C2440_RTCALM_MIN_EN   (1 << 1)      /* 使能ALARM minute */
#define S3C2440_RTCALM_SEC_EN   (1 << 0)      /* 使能ALARM second */

 /* rtc 硬件中断序号 */

#define S3C2440_RTCTICK_IRQIDX  8             /* RTC 节拍硬件中断序号 */
#define S3C2440_RTCALM_IRQIDX   30            /* RTC 闹钟硬件中断序号 */

/* BCD 和 BIN 互相转换 */

#define BCD2BIN(val)            (((val) & 0x0f) + ((val) >> 4) * 10)
#define BIN2BCD(val)            ((((val) / 10) << 4) + (val) % 10)
#define BCD_TO_BIN(val)         ((val) = BCD2BIN (val))
#define BIN_TO_BCD(val)         ((val) = BIN2BCD (val))

/* 驱动控制码 */

enum RTC_IOCTL_CMD
    {
    RTC_IOCTL_SETTIME = 0,      /* 设置时间 */
    RTC_IOCTL_SETIRQTICK,       /* 设置中断请求节拍 */
    RTC_IOCTL_SETALARM,         /* 设置闹钟 */
    };

#endif
